package com.example.project;

import java.io.IOException;
import java.util.Locale;

import com.example.project.model.Comer;
import com.example.service.ComerParcelable;

import android.location.Geocoder;
import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Form_DB_Insert extends Activity {
	
	EditText name;
	EditText phone;
	EditText dir;
	EditText img;
	Button ok;
	Button clean;
	String resname;
	String resphone;
	String resdir;
	String resimg;

	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_form__db__insert);
		
		name=(EditText) findViewById(R.id.editFormRestauranteName);
		phone=(EditText) findViewById(R.id.editFormRestaurantePhone);
		dir=(EditText) findViewById(R.id.editFormRestauranteDirection);
		img=(EditText) findViewById(R.id.editFormRestauranteImg);
		ok=(Button) findViewById(R.id.buttonGuardar);
		//clean=(Button) findViewById(R.id.buttonLimpiar);
		
		ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				resname=name.getText().toString();
				resphone=phone.getText().toString();
				resdir=dir.getText().toString();
				resimg=img.getText().toString();
			
				Comer c = new Comer();
				c.setNombre(resname);
				c.setDireccion(resdir);
				c.setFoto(resimg);
				c.setTelefono(resphone);

				ComerParcelable cp = new ComerParcelable(0,"user",c);
				Bundle b = new Bundle();
				b.putParcelable("RestaurantParcelable",cp);
				Message msg = Message.obtain(null, DateBaseService.MSG_REGISTER_RESTAURANT, 0, 0);
				msg.setData(b);
				try {
					MainActivity.mService.send(msg);
				} catch (RemoteException e) {
					e.printStackTrace();
				}
				
				Intent a = new Intent(v.getContext(), Project_Menu.class);
				v.getContext().startActivity(a);
				
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_form__db__insert, menu);
		return true;
	}

}
